/**
 * Created by hxpeng on 2017/3/24.
 */
(function () {
    'use strict';

    angular.module('App.pages.member')
        .controller('EntrustInfoCtrl', EntrustInfoCtrl);

    function EntrustInfoCtrl(entrustId,$scope,$state,EntrustModel,AppUtils,LoginAccountAuth) {

        var vm = this;
        vm.loginAccount = {};
        vm.entrust = {};

        LoginAccountAuth.getAccount()
            .then(function(data){
                vm.loginAccount = data;
                vm.init();
            });

        vm.init = function(){
            if(!AppUtils.isUndefinedOrNull(entrustId)){
                EntrustModel.getEntrustInfo({entrustId: entrustId}).$promise.then(function(response){
                    if(response.stat == 'err'){
                        AppUtils.showAlert(response.msg);
                    }else{
                        vm.entrust = response.entrust;
                    }
                })
            }else{
                AppUtils.showAlert("未找到该嘱托！");
                AppUtils.goBack();
            }
        }


        $scope.executeEntrust = function(){
            if(!AppUtils.isUndefinedOrNull(vm.entrust.id)){
                EntrustModel.executedEntrust({entrustId:vm.entrust.id}).$promise.then(function(response){
                    if(response.stat == 'err'){
                        AppUtils.showAlert("执行失败：" + response.msg);
                    }else if(response.stat == 'success'){
                        AppUtils.showAlert("成功修改嘱托状态！");
                        vm.init();
                    }
                })
            }
        }
    }

})();